/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package View;

import Controller.PaiementController;
import Controller.SejourController;
import Model.Agenda;
import Model.Categorie;
import Model.Sejour;
import java.beans.PropertyChangeEvent;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Hugo
 */
public class ModifierSejour extends AbstractViewPanel {

    /**
     * Creates new form ModifierSejour
     */
    private SejourController controller;
    private Sejour sejour = null;
    
    public ModifierSejour(SejourController controller) {
        initComponents();
        this.controller = controller;
        this.tblChambreDispo.setEnabled(false);
        this.tblChambreSejour.setEnabled(false);
        this.btnRemplacer.setEnabled(false);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        txtNum = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        btnChercher = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblChambreSejour = new javax.swing.JTable();
        jLabel2 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        tblChambreDispo = new javax.swing.JTable();
        jLabel3 = new javax.swing.JLabel();
        btnRemplacer = new javax.swing.JButton();

        jLabel1.setText("Numéro de séjour:");

        btnChercher.setText("Chercher");
        btnChercher.setToolTipText("");
        btnChercher.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnChercherMouseClicked(evt);
            }
        });

        tblChambreSejour.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane1.setViewportView(tblChambreSejour);

        jLabel2.setText("Chambres du séjour (sélectionner la chambre à changer)");

        tblChambreDispo.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane2.setViewportView(tblChambreDispo);

        jLabel3.setText("Chambres disponibles (Sélectionner la chambre pour remplacer)");

        btnRemplacer.setText("Remplacer");
        btnRemplacer.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnRemplacerMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(35, 35, 35)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtNum, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(59, 59, 59)
                        .addComponent(btnChercher)))
                .addGap(110, 110, 110)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(11, 11, 11)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 261, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 260, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addComponent(jLabel2))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 31, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jLabel3, javax.swing.GroupLayout.Alignment.TRAILING))
                .addContainerGap(195, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(btnRemplacer)
                .addGap(327, 327, 327))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(51, 51, 51)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtNum, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel1))
                        .addGap(18, 18, 18)
                        .addComponent(btnChercher))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(23, 23, 23)
                        .addComponent(jLabel2)
                        .addGap(18, 18, 18)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(52, 52, 52)
                        .addComponent(jLabel3)
                        .addGap(18, 18, 18)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 143, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(18, 18, 18)
                .addComponent(btnRemplacer)
                .addContainerGap(29, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void btnChercherMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnChercherMouseClicked
        try{
            sejour = null;
            sejour = Agenda.getInstance().TrouverSejour(Integer.parseInt(this.txtNum.getText()));
            if(sejour == null){
                JOptionPane.showMessageDialog(this, "Le séjour chercher n'existe pas.");
            }
            else{
                this.tblChambreDispo.setEnabled(true);
                this.tblChambreSejour.setEnabled(true);
                this.btnRemplacer.setEnabled(true);
                populerTableSejour();
                populerTableChambreLibre();
            }
        }
        catch( NumberFormatException e){
            JOptionPane.showMessageDialog(this, "Vous dever entrer un entier comme numéro de séjour.");
        }
        
    }//GEN-LAST:event_btnChercherMouseClicked

    private void btnRemplacerMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnRemplacerMouseClicked
        // TODO add your handling code here:
    }//GEN-LAST:event_btnRemplacerMouseClicked

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnChercher;
    private javax.swing.JButton btnRemplacer;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTable tblChambreDispo;
    private javax.swing.JTable tblChambreSejour;
    private javax.swing.JTextField txtNum;
    // End of variables declaration//GEN-END:variables

    private void populerTableSejour(){
        String[][] listeChambre = null;

        listeChambre = Agenda.getInstance().lireChambreSejour(sejour.getNum());
         
        String[] celNames;
        
        celNames = new String[2];
        celNames[0] = "Numéro de la chambre";
        celNames[1] = "Catégorie";

        JTable jtbl = new JTable(listeChambre, celNames);
        this.tblChambreSejour.setModel(new DefaultTableModel());
        this.tblChambreSejour.setModel(jtbl.getModel());        
    }
    
    private void populerTableChambreLibre(){
         String[][] listeChambre = null;

        listeChambre = Agenda.getInstance().AfficherChambreLibreParCategorie(sejour.getDateDebut(), sejour.getDateFin());
         
        String[] celNames;
        
        celNames = new String[2];
        celNames[0] = "Numéro de la chambre";
        celNames[1] = "Catégorie";

        JTable jtbl = new JTable(listeChambre, celNames);
        this.tblChambreDispo.setModel(new DefaultTableModel());
        this.tblChambreDispo.setModel(jtbl.getModel());      
    }
    
     @Override
    public void modelPropertyChange(PropertyChangeEvent evt) {
        switch(evt.getPropertyName()){
           
        }
    }
}
